﻿using System;
using Autodesk.AutoCAD.DatabaseServices;

namespace Dmo_lc_2.Shape
{
    class ShapeFactory
    {
        public static BaseShape genShapeByEntity(Transaction tr ,DBObject dbobj ) {
            if (dbobj.IsErased) {
                Console.WriteLine("erased item");
                return null;
            }
                
            BaseShape bs = null;

            if (dbobj is Line)
            {
                Line lineEntity = dbobj as Line;
                bs = new LineShape(lineEntity, tr);
            }
            else if (dbobj is Circle)
            {
                Circle circleEntity = dbobj as Circle;
                bs = new CircleShape(circleEntity, tr);
            }
            else if (dbobj is Arc)
            {
                Arc arcEntity = dbobj as Arc;
                bs = new ArcShape(arcEntity, tr);
            }
            else if (dbobj is Polyline)
            {
                Polyline plEntity = dbobj as Polyline;
                bs = new PolylineShape(plEntity, tr);
            }
            else if (dbobj is DBText)
            {
                DBText dbtEntity = dbobj as DBText;
                bs = new DBTextShape(dbtEntity, tr);
            }
            else if (dbobj is MText)
            {
                MText mtEntity = dbobj as MText;
                bs = new MTextShape(mtEntity, tr);
            }
            else if (dbobj is BlockReference)
            {
                BlockReference br = dbobj as BlockReference;
                bs = new BlockReferenceShape(br, tr);
            }
            else if (dbobj is Ellipse)
            {
                Ellipse ellipseEntity = dbobj as Ellipse;
                bs = new EllipseShape(ellipseEntity, tr);
            }
            else if (dbobj is AlignedDimension)
            {
                AlignedDimension alignedDimension = dbobj as AlignedDimension;
                bs = new AlignedDimensionShape(alignedDimension, tr);
            }
            else if (dbobj is RotatedDimension)
            {
                RotatedDimension alignedDimension = dbobj as RotatedDimension;
                bs = new RotatedDimensionShape(alignedDimension, tr);
            }
            else if (dbobj is Hatch)
            {
                Hatch ha = dbobj as Hatch;
                bs = new HatchShape(ha, tr);
            }
            //            else if (dbobj is LineAngularDimension2)
            //            {
            //                LineAngularDimension2 dimension = dbobj as LineAngularDimension2;
            //                bs = new LineAngularDimension(dimension, tr);
            //            }
            else if (dbobj is Solid)
            {
                Solid sd = dbobj as Solid;
                bs = new SolidShape(sd, tr);
            }
            //            Solid solid;
            else if (dbobj is MLeader) {
                MLeader ml = dbobj as MLeader;
                bs = new MLeaderShape(ml, tr);
            }
            // mline
            else if (dbobj is Mline)
            {
                Mline ml = dbobj as Mline;
                bs = new MlineShape(ml, tr);
            }
            return bs;
        }
    }
}
